package Wizard.Android;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.Phones;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;;
@SuppressWarnings("deprecation")
public class tongcunlu extends ListActivity {
	 private ListView listview;
	 private TextView textview;
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.tongxunlu);
	        Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null, null);
	        startManagingCursor(c); 
	        //listview =  (ListView)findViewById(R.id.listvew1);
	        ListAdapter adapter = new SimpleCursorAdapter(this,
	                android.R.layout.simple_list_item_2, c, 
	                        new String[] { Phones.NAME, Phones.NUMBER }, 
	                        new int[] { android.R.id.text1, android.R.id.text2 });
	       setListAdapter(adapter);
	        
	        
	        /*OnItemClickListener listener = new OnItemClickListener(){
	        	

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
						long arg3) {
					// TODO Auto-generated method stub
					Bundle extras = getIntent().getExtras();
			        String str = extras.getString("text");
			        textview=(TextView)arg1.findViewById(android.R.id.text2);
					String str1= (String)textview.getText();
			        Uri uri = Uri.parse("smsto:"+str1);
			      Intent it = new Intent(Intent.ACTION_SENDTO,uri);
			      it.putExtra("sms_body", str);
			      startActivity(it);
				}
	        };*/
	        //listview.setOnItemClickListener(listener);
	        
			
	    }
		@Override
		protected void onListItemClick(ListView l, View v, int position, long id) {
			// TODO Auto-generated method stub
			super.onListItemClick(l, v, position, id);
			Bundle extras = getIntent().getExtras();
	        String str = extras.getString("text");
	        textview=(TextView)v.findViewById(android.R.id.text2);
			String str1= (String)textview.getText();
	        Uri uri = Uri.parse("smsto:"+str1);
	      Intent it = new Intent(Intent.ACTION_SENDTO,uri);
	      it.putExtra("sms_body", str);
	      startActivity(it);
		}
}
